package com.puzzletest.net;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;

import com.puzzletest.bean.General;
import com.puzzletest.bean.ImageInfoList;

public class LoadData {
	public static String BASE_URL = "http://192.168.11.130/Project/Admin/index.php";
	
	/**
	 * 下载图片信息
	 * @return
	 */
	public static ImageInfoList getImageInfo(String templateid){
		List<NameValuePair> nameValue = new ArrayList<NameValuePair>();
		nameValue.add(new BasicNameValuePair("templateid", templateid));
		
		JSONObject jsonObject = ApiRequset.post(BASE_URL+"/down/", nameValue);
		
		return new ImageInfoList(jsonObject);
	}
	
	/**
	 * 上传图片信息
	 * @param scale
	 * @param rotation
	 * @param rotationpoint
	 * @param pointarray
	 * @return
	 */
	public static General putImageInfo(String scale, String rotation, String rotationpoint, String pointarray){
		List<NameValuePair> nameValue = new ArrayList<NameValuePair>();
		nameValue.add(new BasicNameValuePair("scale", scale));
		nameValue.add(new BasicNameValuePair("rotation", rotation));
		nameValue.add(new BasicNameValuePair("rotationpoint", rotationpoint));
		nameValue.add(new BasicNameValuePair("pointarray", pointarray));
		
		JSONObject jsonObject = ApiRequset.post(BASE_URL, nameValue);
		return new General(jsonObject);
		
	}
	
	public static General putImageInfoMore(List<Map<String, String>> datas){
		General general = null;
		for(int i =0 ;i<datas.size() ; i++){
			Map<String, String> map = datas.get(i);
			List<NameValuePair> nameValue = new ArrayList<NameValuePair>();
			nameValue.add(new BasicNameValuePair("scale", map.get("scale")));
			nameValue.add(new BasicNameValuePair("rotation", map.get("rotation")));
			nameValue.add(new BasicNameValuePair("rotationpoint", map.get("rotationpoint")));
			nameValue.add(new BasicNameValuePair("pointarray", map.get("pointarray")));
			nameValue.add(new BasicNameValuePair("name", map.get("name")));
			
			JSONObject jsonObject = ApiRequset.post(BASE_URL, nameValue);
			
			general = new General(jsonObject);
			if(general.getStatus() != 1){
				return general;
			}
		}
		
		if(general == null){
			JSONObject jsonObject = new JSONObject();
			try {
				jsonObject.put(General.STATUS, -111111);
				jsonObject.put(General.MESSAGE, "保存失败...");
			} catch (JSONException e) {
				e.printStackTrace();
			}
			return new General(jsonObject);
		}else{
			return general;
		}
		
	}
	
	
}
